﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Data;
using EZCRS.HCMS.Entity;
using System.Data;
using System.Data.SqlClient;

namespace EZCRS.HCMS.SqlClient
{
    public class sql_AdmLevelSetUp:MainBase
    {
        private string SqlStr = "";

        /// <summary>
        /// 保存级别等级
        /// </summary>
        /// <param name="levelid"></param>
        /// <param name="levelsort"></param>
        /// <returns></returns>
        public bool savelevelsort(int levelid, int levelsort)
        {
            SqlStr = "update hfg_levelsetup set levelclass=" + levelsort.ToString() + " where lvlid=" + levelid.ToString() + "";
            if (ExecSql.SqlExecNoquery(SqlStr) > 0)
                return true;
            else
                return false;
        }
        #region 常客等级设置信息列表
        /// <summary>
        /// 返回所有常客等级
        /// </summary>
        /// <param name="OrgId">组织编号 0 为超级管理员</param>
        /// <param name="OrgType">组织类型 0=集团 1=酒店 3=hubs1</param>
        /// <returns></returns>
        public DataTable LevelSetUp_List(string OrgId, string OrgType)
        {
            if (OrgType == "3")
                SqlStr = "select * from hfg_levelsetup where orgid=0 order by levelclass";
            else if (OrgType == "0")
                SqlStr = "select * from hfg_levelsetup where orgid=" + OrgId + " and orgtype=0 order by levelclass";
            else
                SqlStr = "select * from hfg_levelsetup where orgid=" + OrgId + " and orgtype=1 order by levelclass";
            DataTable dt = ExecSql.GetDataSet(SqlStr).Tables[0];

            if (dt != null)
                return dt;
            else
                return null;
        }
        #endregion
        #region 等级设置信息添加、修改
        /// <summary>
        /// 修改或添加等级设置信息
        /// </summary>
        /// <returns></returns>
        public bool LevelSetUp_Add(string Orgid, string Orgtype, string Lvlname, string Lvlimg, string Startscore, string Endscore, string Days, string Hotels, string Lvlcomment, string Inuser, string Indate, string Lvlcount, string Lvlid)
        {
            SqlParameter[] pam = new SqlParameter[12];
            pam[0] = new SqlParameter("@orgid", Orgid);
            pam[1] = new SqlParameter("@orgtype", Orgtype);
            pam[2] = new SqlParameter("@lvlname", Lvlname);
            pam[3] = new SqlParameter("@lvlimg", Lvlimg);
            pam[4] = new SqlParameter("@startscore", Startscore);
            pam[5] = new SqlParameter("@endscore", Endscore);
            pam[6] = new SqlParameter("@days", Days);
            pam[7] = new SqlParameter("@hotels", Hotels);
            pam[8] = new SqlParameter("@lvlcomment", Lvlcomment);
            pam[9] = new SqlParameter("@inuser", Inuser);
            pam[10] = new SqlParameter("@indate", Indate);
            pam[11] = new SqlParameter("@lvlcount", Lvlcount);


            if (Lvlid != "")
                SqlStr = "update hfg_levelsetup set orgid=@orgid,orgtype=@orgtype,lvlname=@lvlname,lvlimg=@lvlimg,startscore=@startscore,endscore=@endscore,days=@days,hotels=@hotels,lvlcomment=@lvlcomment,inuser=@inuser,indate=@indate,lvlcount=@lvlcount where lvlid=" + Lvlid + "";
            else
                SqlStr = "insert into hfg_levelsetup(orgid,orgtype,lvlname,lvlimg,startscore,endscore,days,hotels,lvlcomment,inuser,indate,lvlcount) values(@orgid,@orgtype,@lvlname,@lvlimg,@startscore,@endscore,@days,@hotels,@lvlcomment,@inuser,@indate,@lvlcount)";
            if (ExecSql.SqlExecNoquery(SqlStr, pam) > 0)
                return true;
            else
                return false;
        }
        #endregion
        #region 等级设置Info数据的显示,显示一条数据
        public DataRow LevelSetUp_Item(string Lvlid)
        {
            try
            {
                return ExecSql.GetDataSet("select * from hfg_levelsetup where lvlid=" + Lvlid).Tables[0].Rows[0];
            }
            catch
            {
                return null;
            }
        }
        #endregion
        #region 等级设置的删除
        public bool LevelSetUp_Del(string Lvlid)
        {
            string sql = "", msg = "";
            sql = "delete from hfg_levelsetup where lvlid=" + Lvlid + "";
            if (ExecSql.SqlExecNoquery(sql) > 0)
                return true;
            else
                return false;
        }
        #endregion
    }
}
